# Build monitor

if(BUILD_OUTPUT STREQUAL "all" )
    install(CODE "execute_process(COMMAND make -f Makefile -j4 BUILD_TARGET=${BUILD_TARGET} BUILD_OS=${BUILD_OS} BUILD_EVE_FIRMWARE=${BUILD_EVE_FIRMWARE} WORKING_DIRECTORY ${OCL_MONITOR_DIR})")
endif()

# Install monitor, linker command file, and symbols

if(BUILD_OUTPUT STREQUAL "all" OR BUILD_OUTPUT STREQUAL "lib")
    if (${BUILD_TARGET} MATCHES "ARM_K2H")
        install(FILES monitor_evmk2h/dsp0.out monitor_evmk2h/dsp1.out monitor_evmk2h/dsp2.out monitor_evmk2h/dsp3.out monitor_evmk2h/dsp4.out monitor_evmk2h/dsp5.out monitor_evmk2h/dsp6.out monitor_evmk2h/dsp7.out DESTINATION ${SHARE_PATH}/opencl ${OCL_FPERMS})
        install(FILES monitor_evmk2h/dsp0.out DESTINATION ${SHARE_PATH}/opencl RENAME dsp.out ${OCL_FPERMS})
        install(FILES monitor_evmk2h/dsp0.syms.obj DESTINATION ${SHARE_PATH}/opencl RENAME dsp_syms.obj ${OCL_FPERMS})
        install(FILES monitor_evmk2h/dsp0.syms DESTINATION ${SHARE_PATH}/opencl RENAME dsp.syms ${OCL_FPERMS})
    elseif (${BUILD_TARGET} MATCHES "ARM_K2L")
        install(FILES monitor_evmk2l/dsp0.out monitor_evmk2l/dsp1.out monitor_evmk2l/dsp2.out monitor_evmk2l/dsp3.out DESTINATION ${SHARE_PATH}/opencl ${OCL_FPERMS})
        install(FILES monitor_evmk2l/dsp0.out DESTINATION ${SHARE_PATH}/opencl RENAME dsp.out ${OCL_FPERMS})
        install(FILES monitor_evmk2l/dsp0.syms.obj DESTINATION ${SHARE_PATH}/opencl RENAME dsp_syms.obj ${OCL_FPERMS})
        install(FILES monitor_evmk2l/dsp0.syms DESTINATION ${SHARE_PATH}/opencl RENAME dsp.syms ${OCL_FPERMS})
    elseif (${BUILD_TARGET} MATCHES "ARM_K2E")
        install(FILES monitor_evmk2e/dsp0.out DESTINATION ${SHARE_PATH}/opencl ${OCL_FPERMS})
        install(FILES monitor_evmk2e/dsp0.out DESTINATION ${SHARE_PATH}/opencl RENAME dsp.out ${OCL_FPERMS})
        install(FILES monitor_evmk2e/dsp0.syms.obj DESTINATION ${SHARE_PATH}/opencl RENAME dsp_syms.obj ${OCL_FPERMS})
        install(FILES monitor_evmk2e/dsp0.syms DESTINATION ${SHARE_PATH}/opencl RENAME dsp.syms ${OCL_FPERMS})
    elseif (${BUILD_TARGET} MATCHES "ARM_AM57")
        if (NOT (${BUILD_OS} MATCHES "SYS_BIOS")) #Linux
            install(FILES monitor_am57x/dsp0.syms DESTINATION /usr/share/ti/opencl RENAME dsp.syms ${OCL_FPERMS})
            install(FILES monitor_am57x/dsp0.syms.obj DESTINATION /usr/share/ti/opencl RENAME dsp_syms.obj ${OCL_FPERMS})
            install(FILES monitor_am57x/dsp0.out  DESTINATION /usr/share/ti/opencl RENAME dsp.out  ${OCL_FPERMS})
            install(FILES monitor_am57x/dsp0.out DESTINATION /lib/firmware RENAME dra7-dsp1-fw.xe66 ${OCL_FPERMS})
            install(FILES monitor_am57x/dsp1.out DESTINATION /lib/firmware RENAME dra7-dsp2-fw.xe66 ${OCL_FPERMS})
        else() # RTOS
            install(FILES monitor_am57x_rtos/dsp0.syms DESTINATION /usr/share/ti/opencl RENAME dsp.syms ${OCL_FPERMS})
            install(FILES monitor_am57x_rtos/dsp0.syms.obj DESTINATION /usr/share/ti/opencl RENAME dsp_syms.obj ${OCL_FPERMS})
            install(FILES monitor_am57x_rtos/dsp0.out DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
            install(FILES monitor_am57x_rtos/dsp1.out DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
            install(FILES libDSPMonitor.ae66 DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
            install(FILES ../builtins/dsp.lib DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
            install(FILES ../libm/libm.lib DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
            install(FILES cmds/monitor.am57x_rtos.cmd DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
        endif()
    elseif (${BUILD_TARGET} MATCHES "ARM_K2G")
        install(FILES monitor_evmk2g/dsp0.out DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
        install(FILES monitor_evmk2g/dsp0.out DESTINATION /usr/share/ti/opencl RENAME dsp.out ${OCL_FPERMS})
        install(FILES monitor_evmk2g/dsp.syms DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
        install(FILES monitor_evmk2g/dsp_syms.obj DESTINATION /usr/share/ti/opencl ${OCL_FPERMS})
    else()
        message(FATAL_ERROR "invalid BUILD_TARGET ${BUILD_TARGET}")
    endif()
endif()
